package org.wang.generalcode.modules.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wang.generalcode.modules.exam.pojo.entity.SubjectInfoEntity;
import org.wang.generalcode.modules.exam.pojo.param.SubjectInfoParams;
import org.wang.generalcode.modules.exam.pojo.vo.SubjectInfoVO;
import org.wang.generalcode.modules.exam.service.SubjectInfoService;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.PageResult;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

import java.util.List;

/**
 * 科目表前端控制层
 *
 * @author wz
 * @since 2024-11-22
 */
@Tag(name = "科目表接口")
@RestController
@RequestMapping("exam/subject_info")
@RequiredArgsConstructor
public class SubjectInfoController {

    private final SubjectInfoService subjectinfoService;

    @Operation(summary = "科目表分页列表")
    @GetMapping("/page")
    public PageResult<SubjectInfoVO> getSubjectInfoPage(SubjectInfoParams queryParams, Query query) {
        IPage<SubjectInfoVO> result = subjectinfoService.getSubjectInfoPage(Condition.getPage(query),queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "科目表列表")
    @GetMapping("/list")
    public Result getSubjectInfoList(SubjectInfoParams queryParams) {
        List<SubjectInfoVO> result = subjectinfoService.getSubjectInfoList(queryParams);
        return Result.success(result);
    }

    @Operation(summary = "新增科目表")
    @PostMapping("/save")
    public Result saveSubjectInfo(@RequestBody @Valid SubjectInfoEntity formData) {
        boolean result = subjectinfoService.save(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取科目表表单数据")
    @GetMapping("/detail")
    public Result<SubjectInfoEntity> getSubjectInfoForm(
        @Parameter(name = "主键", required = true) @RequestParam Long id
    ) {
            SubjectInfoEntity formData = subjectinfoService.getById(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改科目表")
    @PutMapping(value = "/update")
    public Result updateSubjectInfo(
            @RequestBody SubjectInfoEntity entity
    ) {
        boolean result = subjectinfoService.updateById(entity);
        return Result.judge(result);
    }

    @Operation(summary = "删除科目表")
    @DeleteMapping("/remove")
    public Result deleteSubjectInfos(
            @Parameter(name = "主键集合", required = true) @RequestParam String ids
    ) {
        boolean result = subjectinfoService.removeBatchByIds(Func.toLongList(ids));
        return Result.judge(result);
    }
}
